package com.liu.stockmarket.ui.statistics.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.liu.stockmarket.R
import com.liu.stockmarket.utils.getString
import com.liu.stockmarket.utils.money
import com.liu.stockmarket.utils.textColor
import java.math.BigDecimal

class StatisticsAdapter : BaseQuickAdapter<StatisticsAdapter.Item, BaseViewHolder>(
    R.layout.item_statistics
) {


    override fun convert(holder: BaseViewHolder, item: Item) {
        holder.setText(R.id.tv_title, item.title)
        val content = holder.getView<TextView>(R.id.tv_content)

        if (item.money) {

            content.textColor(context,item.content)
            content.text = "${item.content.getString(2)}" + if (item.percent!=null && item.percent != BigDecimal.ZERO){
                "(${item.percent?.getString(2)?:"0"}%)"
            }else{
                ""
            }


        } else {
            content.setTextColor(this.context.getColor(R.color.black))
            content.text = item.content.getString()
        }

    }

    data class Item(
        val title: String,
        val content: BigDecimal,
        val percent:BigDecimal?=null,
        val money: Boolean = true

    )
}